package com.bjsj.pro.tools;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileUtil {

    //系统保存截图的路径
    public static final String SCREENCAPTURE_PATH = "微商助手" + File.separator + "微商助手" + File.separator;
    public static final String SCREENSHOT_NAME = "微商助手";
    static {
        //初始化文件夹
        createVoiceDir();
    }
    public static String getAppPath(Context context) {

        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            return Environment.getExternalStorageDirectory().toString();
        } else {
            return context.getFilesDir().toString();
        }
    }

    public static File createVoiceDir() {
        //判断目录创建
        Log.d("wwwwwwww","判断目录创建");
        File parentDir = new File(Constants.PACKAGE_ROOT);
        if (!parentDir.exists()) {
            Log.d("wwwwwwww","创建成功1");
            //不存在创建新目录
            parentDir.mkdirs();
        }else {
            Log.d("wwwwwwww","已创建1");

        }
        //判断目录创建

        File mediaDir = new File(Constants.VOICE_FILE);
        if (!mediaDir.exists()) {
            Log.d("wwwwwwww","创建成功2");
            //不存在创建新目录
            mediaDir.mkdirs();
        }else {
            Log.d("wwwwwwww","已创建2");

        }
        return mediaDir;
    }

    public static String getScreenShots(Context context) {

        StringBuffer stringBuffer = new StringBuffer(getAppPath(context));
        stringBuffer.append(File.separator);

        stringBuffer.append(SCREENCAPTURE_PATH);

        File file = new File(stringBuffer.toString());

        if (!file.exists()) {
            file.mkdirs();
        }
        return stringBuffer.toString();
    }

    public static String getScreenShotsName(Context context) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");

        String date = simpleDateFormat.format(new Date());

        StringBuffer stringBuffer = new StringBuffer(getScreenShots(context));
        stringBuffer.append(SCREENSHOT_NAME);
        stringBuffer.append("_");
        stringBuffer.append(date);
        stringBuffer.append(".png");
        return stringBuffer.toString();
    }
}
